import { ECSCmp } from "../../lib/kgame/ecs/ECSCmp";
import { SnakeHeadCmp } from "./SnakeHeadCmp";

/**
 * 蛇组件
 */
export class SnakeCmp extends ECSCmp {

    /** 蛇id */
    snakeId: number;
    /** 蛇名 */
    name: string;
    /** 重生cd */
    respawnCd: number;
    /** 蛇头 */
    head: SnakeHeadCmp;
    /** 凶手 */
    killer: SnakeCmp | string;
    /** 移除标志 */
    doRemove = false;

    /** 死亡 */
    get death() { return !this.head; }

    /**
     * 初始化蛇组件
     * @param snakeId 蛇id
     * @param name 蛇名
     * @param respawnCd 重生cd
     */
    onCreate(snakeId: number, name: string, respawnCd = 0) {
        this.snakeId = snakeId;
        this.name = name;
        this.respawnCd = respawnCd;
        return this;
    }

    protected onClear(): void {
        this.head = null;
        this.killer = null;
        this.doRemove = false;
    }

}